import decimal
import json
from datetime import datetime

from flask import jsonify

from py.commonResponse.ResponseCode import ResponseCode


def createForSuccessWMD(msg, data):
    return CommonResponse(ResponseCode.SUCCESS.value, msg, data).to_dict()


def createForSuccessWM(msg):
    return CommonResponse(ResponseCode.SUCCESS.value, msg).to_dict()


def createForErrorWMD(msg, data):
    return CommonResponse(ResponseCode.ERROR.value, msg, data).to_dict()


def createForErrorWM(msg):
    return CommonResponse(ResponseCode.ERROR.value, msg).to_dict()


class CommonResponse:
    def __init__(self, code, msg, data=None):
        self.code = code
        self.msg = msg
        self.data = data

    def to_dict(self):
        return jsonify({"code": self.code, "msg": self.msg, "data": self.data})


